﻿using UnityEngine;
using System.Collections;

public class WindScript : MonoBehaviour {

	//MOVEMENT
	private bool _onMoving;
	private float _movementTime;
	public float _minTimeForTheWindToChange;
	public float _maxTimeForTheWindToChange;
	//[HideInInspector]
	public Vector3 _movementDirection;
	private float _randomX;
	private float _randomY;
	public float _minStrenght;
	public float _maxStrenght;
	private float _movementStrenght;


	// Use this for initialization
	void Start () {
		//Variable Initialisation
		_onMoving = true;
		_movementTime = 0;
		_movementDirection = new Vector3 (0, 0, 0);
		_movementStrenght = 0;

		//Coroutine Initialisation
		StartCoroutine ("MovementChanging");
	}
	
	void Update () {
		//Assign Random for Wind Direction
		_randomX = Random.Range (-1.0f, 1.0f);
		_randomY = Random.Range (-1.0f, 1.0f);

		Movement ();
	}

	void Movement (){
		this.transform.Translate (_movementDirection * _movementStrenght * Time.deltaTime);
	}

	IEnumerator MovementChanging (){
		while(_onMoving){
			//NEW TIME AND DIRECTION
			_movementDirection = new Vector3 (_randomX, 0 , _randomY);
			_movementTime = Random.Range(_minTimeForTheWindToChange, _maxTimeForTheWindToChange);
			_movementStrenght = Random.Range(_minStrenght,_maxStrenght);
			
			print ("Direction: " + _movementDirection + " Force: " + _movementStrenght + " Time: " + _movementTime);
			yield return new WaitForSeconds (_movementTime);
		}
	}
}
